/*
 * Copyright 2012-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.web.servlet.error;

import java.util.Collections;
import java.util.Map;

import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

/**
 * 提供对错误属性的访问，这些属性可以用于记录日志或展示给用户。
 *
 * @author Phillip Webb
 * @author Scott Frederick
 * @since 2.0.0
 * @see DefaultErrorAttributes
 */
public interface ErrorAttributes {

	/**
	 * {@link javax.servlet.http.HttpServletRequest#getAttribute(String)} 中保存
	 * 由 {@code ErrorAttributes} 实现类解析的错误的请求属性名称。
	 * @since 2.5.0
	 */
	String ERROR_ATTRIBUTE = ErrorAttributes.class.getName() + ".error";

	/**
	 * 返回一个包含错误属性的 {@link Map}。该映射可以用作错误页面的 {@link ModelAndView} 的模型，
	 * 或通过 {@link ResponseBody @ResponseBody} 返回。
	 * @param webRequest 源请求
	 * @param options 错误属性内容的选项
	 * @return 错误属性的映射
	 * @since 2.3.0
	 */
	default Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
		return Collections.emptyMap();
	}

	/**
	 * 返回错误的根本原因，或者在无法提取错误时返回 {@code null}。
	 * @param webRequest 源请求
	 * @return 引发错误的 {@link Exception}，或 {@code null}
	 */
	Throwable getError(WebRequest webRequest);

}
